import { createSlice } from "@reduxjs/toolkit"
import Axios from 'axios'

const userStore = createSlice({
  name: "user",
  initialState: {
    guid: 'xx2231xx' as string,
    list:[]
  },
  reducers: {
    getUserGuid(state,actions) {
      state.guid=actions.payload
    },
    setList(state, actions) {
      state.list=actions.payload
    }
  },
})



const { getUserGuid ,setList} = userStore.actions
export { getUserGuid,setList }

const getListApi = () => {
  return  (dispatch: () => void) => {
    Axios.get('http://geek.itheima.net/v1_0/channels').then(res => {
      dispatch(setList(res.data.data.channels))
    })
  }
}
export { getListApi }
const reducer = userStore.reducer
export default reducer